<?php
App::uses('AppController', 'Controller');
/**
 * CriteriosEvaluations Controller
 *
 * @property CriteriosEvaluation $CriteriosEvaluation
 */
class CriteriosEvaluationsController extends AppController {
public $uses = array( 'CriteriosEvaluation', 'Evaluation');
/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->CriteriosEvaluation->recursive = 0;
		$this->set('criteriosEvaluations', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->CriteriosEvaluation->exists($id)) {
			throw new NotFoundException(__('Invalid criterios evaluation'));
		}
		$options = array('conditions' => array('CriteriosEvaluation.' . $this->CriteriosEvaluation->primaryKey => $id));
		$this->set('criteriosEvaluation', $this->CriteriosEvaluation->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->CriteriosEvaluation->create();
			if ($this->CriteriosEvaluation->saveAll($this->request->data['CriteriosEvaluation'])) {
				$this->Session->setFlash(__('The criterios evaluation has been saved'));
				print_r($this->request->data);
				//$this->redirect(array('action' => 'index'));
			} else {
				print_r($this->request->data);
				$this->Session->setFlash(__('saddas'.$this->request->data['CriteriosEvaluation']));
			}
		}
		$evaluations = $this->CriteriosEvaluation->Evaluation->find('list');
		$criterios = $this->CriteriosEvaluation->Criterio->find('list');
		$this->set(compact('evaluations', 'criterios'));
	}
	/**
 * add method
 *
 * @return void
 */
	public function add_evaluation() {
		if ($this->request->is('post')) {
			$this->CriteriosEvaluation->create();
			if ($this->CriteriosEvaluation->saveAll($this->request->data['CriteriosEvaluation'])) {
				//$this->Session->setFlash(__('The criterios evaluation has been saved'));
				//print_r($this->request->data);
				$this->redirect('/evaluations/retro/'.$this->request->data['CriteriosEvaluation'][0]['evaluation_id']);
			} else {
				//print_r($this->request->data);
				//$this->Session->setFlash(__('saddas'.$this->request->data['CriteriosEvaluation']));
			}
		}
		$evaluations = $this->CriteriosEvaluation->Evaluation->find('list');
		$criterios = $this->CriteriosEvaluation->Criterio->find('list');
		$this->set(compact('evaluations', 'criterios'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->CriteriosEvaluation->exists($id)) {
			throw new NotFoundException(__('Invalid criterios evaluation'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->CriteriosEvaluation->save($this->request->data)) {
				$this->Session->setFlash(__('The criterios evaluation has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The criterios evaluation could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('CriteriosEvaluation.' . $this->CriteriosEvaluation->primaryKey => $id));
			$this->request->data = $this->CriteriosEvaluation->find('first', $options);
		}
		$evaluations = $this->CriteriosEvaluation->Evaluation->find('list');
		$criterios = $this->CriteriosEvaluation->Criterio->find('list');
		$this->set(compact('evaluations', 'criterios'));
	}
/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit_evaluation($id = null) {
		if (!$this->CriteriosEvaluation->exists($id)) {
			throw new NotFoundException(__('Invalid criterios evaluation'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->CriteriosEvaluation->saveAll($this->request->data['CriteriosEvaluation'])) {
				$this->Session->setFlash(__('The criterios evaluation has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The criterios evaluation could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('CriteriosEvaluation.' . $this->CriteriosEvaluation->primaryKey => $id));
			$this->request->data = $this->CriteriosEvaluation->find('first', $options);
		}
		$evaluations = $this->CriteriosEvaluation->Evaluation->find('list');
		$criterios = $this->CriteriosEvaluation->Criterio->find('list');
		$this->set(compact('evaluations', 'criterios'));
	}	

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->CriteriosEvaluation->id = $id;
		if (!$this->CriteriosEvaluation->exists()) {
			throw new NotFoundException(__('Invalid criterios evaluation'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->CriteriosEvaluation->delete()) {
			$this->Session->setFlash(__('Criterios evaluation deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Criterios evaluation was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
